package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.common.log.service.AsyncSysOperLogService;
import com.atguigu.spzx.manager.mapper.SysOperLogMapper;
import com.atguigu.spzx.model.dto.system.SysOperLogDto;
import com.atguigu.spzx.model.entity.system.SysOperLog;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AsyncSysOperLogServiceImpl implements AsyncSysOperLogService {

    @Autowired
    private SysOperLogMapper sysOperLogMapper;

    @Async      // 异步执行保存日志操作
    @Override
    public void saveSysOperLog(SysOperLog sysOperLog) {
        sysOperLogMapper.insert(sysOperLog);
    }

    @Override
    @Transactional(readOnly = true)
    public PageInfo<SysOperLog> findSysOperLogPage(Integer pageNum, Integer pageSize, SysOperLogDto sysOperLogDto) {
        PageHelper.startPage(pageNum,pageSize);
        List<SysOperLog> sysOperLogList = sysOperLogMapper.selectSysOperLogPage(sysOperLogDto);
        return new PageInfo<>(sysOperLogList);
    }
}